package com.lekang.le.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lekang.common.annotation.Log;
import com.lekang.common.core.controller.BaseController;
import com.lekang.common.core.domain.AjaxResult;
import com.lekang.common.enums.BusinessType;
import com.lekang.le.domain.FamilyMember;
import com.lekang.le.service.IFamilyMemberService;
import com.lekang.common.utils.poi.ExcelUtil;
import com.lekang.common.core.page.TableDataInfo;

/**
 * 客户信息Controller
 * 
 * @author xuan
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/le/member")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    /**
     * 查询客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('le:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(FamilyMember familyMember)
    {
        startPage();
        List<FamilyMember> list = familyMemberService.selectFamilyMemberList(familyMember);
        return getDataTable(list);
    }

    /**
     * 导出客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('le:member:export')")
    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FamilyMember familyMember)
    {
        List<FamilyMember> list = familyMemberService.selectFamilyMemberList(familyMember);
        ExcelUtil<FamilyMember> util = new ExcelUtil<FamilyMember>(FamilyMember.class);
        util.exportExcel(response, list, "客户信息数据");
    }

    /**
     * 获取客户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('le:member:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(familyMemberService.selectFamilyMemberById(id));
    }

    /**
     * 新增客户信息
     */
    @PreAuthorize("@ss.hasPermi('le:member:add')")
    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyMember familyMember)
    {
        return toAjax(familyMemberService.insertFamilyMember(familyMember));
    }

    /**
     * 修改客户信息
     */
    @PreAuthorize("@ss.hasPermi('le:member:edit')")
    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyMember familyMember)
    {
        return toAjax(familyMemberService.updateFamilyMember(familyMember));
    }

    /**
     * 删除客户信息
     */
    @PreAuthorize("@ss.hasPermi('le:member:remove')")
    @Log(title = "客户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(familyMemberService.deleteFamilyMemberByIds(ids));
    }

//    查询
@PreAuthorize("@ss.hasPermi('le:member:list')")
@GetMapping("/listMo")
public TableDataInfo listMo(FamilyMember familyMember)
{
    startPage();
    List<FamilyMember> familyMembers = familyMemberService.selectAll(familyMember);
    return getDataTable(familyMembers);
}

    /**
     * 查询客户信息列表（基于微信用户）
     * 包含客户昵称、手机号、是否签约、服务下单次数、绑定老人姓名、首次登录时间
     */
    @PreAuthorize("@ss.hasPermi('le:member:list')")
    @GetMapping("/listCustomerInfo")
    public TableDataInfo listCustomerInfo(String nickname, String phone)
    {
        startPage();
        List<com.lekang.le.domain.vo.CustomerInfoVO> list = familyMemberService.selectCustomerInfoList(nickname, phone);
        return getDataTable(list);
    }

}
